package main

import (
	"bufio"
	"flag"
	"fmt"
	"os"
	"os/exec"
	"path/filepath"
)

func main() {
	dirpath := parseFlag()
	printBinDir()
	write2RelativePath(dirpath)
}

func parseFlag() string {
	dirpath := flag.String("port", "./", "a dir path you should input")
	flag.Parse()
	return *dirpath
}

func printBinDir() {
	file, _ := exec.LookPath(os.Args[0])
	path, _ := filepath.Abs(file)
	println(path)
}

func write2RelativePath(dirpath string) {
	f, _ := os.Create(dirpath + "test.log")
	w := bufio.NewWriter(f)
	n4, _ := w.WriteString("bufferedn")
	w.Write([]byte("\n"))
	fmt.Printf("写入 %d 个字节\n", n4)
	w.Flush()
	f.Close()
}
